/**
 * @author 徐楠
 * @date 2022/5/26 9:55
 * @version 1.0
 */

package com.xunan.likou;

public class AddOneTenth {
    public static void main(String[] args) {
        //int[] digits = {4, 3, 2, 1};
        int[] digits = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
        int[] ints = plusOne(digits);
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i] + " ");
        }
    }

    public static int[] plusOne(int[] digits) {
        int n = digits.length;
        //从数组最后开始
        for (int i = n - 1; i >= 0; --i) {
            if (digits[i] != 9) {
                System.out.println("digits[i] : " + digits[i]);
                ++digits[i];
                for (int j = i + 1; j < n; ++j) {
                    digits[j] = 0;
                }
                return digits;
            }
        }

        // digits 中所有的元素均为 9
        int[] ans = new int[n + 1];
        ans[0] = 1;
        return ans;

    }
}
